import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_hx/services/app_theme_services.dart';
import 'package:flutter_hx/widgets/view_state_helper.dart';
import 'package:get/get.dart';
import 'account_list_view_logic.dart';

class AccountListView extends StatelessWidget {
  final dynamic accountType;
  final bool isConsume;
  const AccountListView({Key? key,required this.accountType,required this.isConsume}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.put(AccountListViewLogic(),tag: "isConsume=$isConsume");
    logic.queryMap["accountType"]=accountType;
    logic.queryMap["isConsume"]=isConsume;
    logic.onRefresh();
    return Obx((){
        if(logic.viewStatus.value==ViewState.empty){
          return const Center(child: ViewStateEmptyWidget());
        }
        switch(logic.viewStatus.value){
          case ViewState.empty:
            return const Center(child: ViewStateEmptyWidget(paddingTop: 20));
          case ViewState.loading:
            return const Center(child: ViewStateLoadingWidget(paddingTop: 20));
          case ViewState.error:
          case ViewState.noNetwork:
            return Center(child: ViewStateErrorWidget(paddingTop: 20,onPressed: ()=>logic.onRefresh()));
        }
        return EasyRefresh.custom(
          slivers: [
            SliverList(delegate:SliverChildBuilderDelegate((_,i){
              final item=logic.dataSource[i];
              final isCus="-"==item["direction"];
              return Container(
                height: 80,
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child:Column(
                  children: [
                    Expanded(child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text("${item["remark"]}",style: AppThemeServices.textTheme.h14.copyWith(color: Colors.black,fontWeight: FontWeight.w700)),
                            const SizedBox(height: 7),
                            Text("2022.09.05 15:23",style: AppThemeServices.textTheme.h12.copyWith(color: AppThemeServices.appColors.hintTextColor))
                          ],
                        ),
                        Text("${item["direction"]}${item["amount"]}",style: AppThemeServices.textTheme.h14.bold().copyWith(color:isCus?Colors.redAccent:Colors.black,fontSize: 17))
                      ],
                    )),
                    i==logic.dataSource.length-1?const SizedBox():Divider(height: 0.5,color: AppThemeServices.appColors.divider)
                  ],
                ) ,
              );
            },childCount: logic.dataSource.length))
          ],
        );
    });
  }
}
